/*
 * Copyright (c) 2018-2999 湖南洛云网络科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.config.Constant;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.distribution.comment.model.DistributionRecruitSet;
import com.yami.shop.distribution.comment.service.DistributionRecruitSetService;
import com.yami.shop.security.platform.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;

/**
 * @author lgh on 2019/04/01.
 */
@RestController
@RequestMapping("/distribution/distributionRecruitSet")
public class DistributionRecruitSetController {

    @Autowired
    private DistributionRecruitSetService distributionRecruitSetService;

    /**
     * 分页获取
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('distribution:distributionRecruitSet:page')")
    public ResponseEntity<IPage<DistributionRecruitSet>> page(DistributionRecruitSet distributionRecruitSet, PageParam<DistributionRecruitSet> page) {
        IPage<DistributionRecruitSet> list = distributionRecruitSetService.page(page, new LambdaQueryWrapper<DistributionRecruitSet>());
        return ResponseEntity.ok(list);
    }

    /**
     * 获取信息(根据店铺)
     */
    @GetMapping("/info")
    @PreAuthorize("@pms.hasPermission('distribution:distributionRecruit:info')")
    public ResponseEntity<DistributionRecruitSet> getByShopId() {
        return ResponseEntity.ok(distributionRecruitSetService.getByShopId());
    }

    /**
     * 修改
     */
    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionRecruitSet:update')")
    public ResponseEntity<Void> update(@RequestBody @Valid DistributionRecruitSet distributionRecruitSet) {
        distributionRecruitSet.setModifier(SecurityUtils.getSysUser().getUserId());
        distributionRecruitSet.setUpdateTime(new Date());
        distributionRecruitSetService.updateById(distributionRecruitSet);
        distributionRecruitSetService.removeCacheByShopId(Constant.PLATFORM_SHOP_ID);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionRecruit:delete')")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        distributionRecruitSetService.removeById(id);
        return ResponseEntity.ok().build();
    }

//    /**
//	 * 获取信息
//	 */
//	@GetMapping("/info/{id}")
//	//@PreAuthorize("@pms.hasPermission('admin:distributionRecruit:info')")
//	public ResponseEntity<DistributionRecruitSet> info(@PathVariable("id") Long id){
//		DistributionRecruitSet distributionRecruitSet = distributionRecruitSetService.getById(id);
//		return ResponseEntity.ok(distributionRecruitSet);
//	}

//	/**
//	 * 保存
//	 */
//	@PostMapping
//	//@PreAuthorize("@pms.hasPermission('admin:distributionRecruitSet:save')")
//	public ResponseEntity<Void> save(@RequestBody @Valid DistributionRecruitSet distributionRecruitSet){
//		distributionRecruitSet.setShopId(Constant.PLATFORM_SHOP_ID);
//		distributionRecruitSet.setModifier(SecurityUtils.getSysUser().getUserId());
//		distributionRecruitSet.setUpdateTime(new Date());
//		distributionRecruitSetService.save(distributionRecruitSet);
//		return ResponseEntity.ok().build();
//	}
}
